package Sonnet;

import java.awt.Dimension;

import javafx.application.Application;

import javafx.application.Platform;
import javafx.scene.*;
import javafx.scene.Scene;
import javafx.stage.Stage;

import javafx.fxml.FXMLLoader;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.scene.SnapshotParameters;

import java.awt.*;
import java.awt.image.*;
//import java.awt.event.ActionEvent;
import java.awt.Dimension;
import java.lang.Object;
import java.io.InputStream;
import java.io.File;
import java.io.*;
import javax.imageio.ImageIO;//Keep For .png Image Creation
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.ByteBuffer;

import javafx.scene.paint.Color;
import javafx.geometry.Rectangle2D;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.image.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.image.WritableImage.*;
import javafx.scene.input.KeyEvent;
//import javafx.scene.layout.VBox;
import javafx.scene.text.*;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.scene.layout.*;
//import javafx.scene.paint.Color;
//import javafx.scene.shape.*;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

//import java.util.Timer;
//import java.util.TimerTask;
import java.lang.Object.*;
import org.apache.commons.io.*;
import java.io.PrintWriter;
import java.io.PrintStream;
import javax.swing.JFileChooser;
//import javafx.stage.DirectoryChooser;
//import javafx.stage.FileChooser;
import javafx.embed.swing.SwingFXUtils;
//import org.openqa.selenium.By;
//import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;

//import com.sun.tools.javac.api.JavacTaskPool.Worker;

//import org.apache.commons.io.FileUtils;

//import org.openqa.selenium.OutputType;

//import org.openqa.selenium.TakesScreenshot;


import org.jcodec.api.awt.SequenceEncoder;//Keep For .mp4 Video Creation

/*class ColorSlider
{
	public double[] RGB;// = {0,0,0};
	public ColorSlider(double[] RGB)
	{
        this.RGB = RGB;
    }
	public ColorSlider()
	{
        this.RGB = new double[]{0,0,0,0};
	}
	public Object ColorSliderFunction(double ColorInterval, double Loc, ColorSlider ColorBefore, ColorSlider ColorAfter)
	{
		for (int z = 0; z <= 2; z++)
			RGB[z] = ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Loc/ColorInterval + ColorBefore.RGB[z] );
		return new ColorSlider( RGB );
	}
	public Object ColorSliderFunction(double ColorInterval, double Loc, double BrightnessMultiplyer, ColorSlider ColorBefore, ColorSlider ColorAfter)
	{
		if ( BrightnessMultiplyer < 1)
			for (int z = 0; z <= 2; z++)
				RGB[z] = ( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Loc/ColorInterval + ColorBefore.RGB[z] ) * BrightnessMultiplyer);
		else
			for (int z = 0; z <= 2; z++)
			{
				RGB[z] = ( ( (ColorAfter.RGB[z] - ColorBefore.RGB[z]) * Loc/ColorInterval + ColorBefore.RGB[z] ) );
				RGB[z] = ( (255 - RGB[z]) / BrightnessMultiplyer + RGB[z] );
			}
		return new ColorSlider( RGB );
	}
	public void set(double[] RGB) { this.RGB = RGB; }
    public Object get() { return RGB; }
}//*/

public class Sonnet extends Application
{

	@Override
	public void start(Stage stage) throws IOException
	{
		Thread thread = new Thread(() -> {
			try { Thread.sleep(400); }
			catch (InterruptedException exc) { throw new Error("Unexpected interruption", exc); }
			// Update text on FX Application Thread:
			Platform.runLater(new Runnable() {
				@Override
				public void run()
				{
					try { Setup(stage); }
					catch(IOException ie) { ie.printStackTrace(); }
				}
			});
		});
		thread.setDaemon(true);
		thread.start();
	}

	static void Setup(Stage primaryStage) throws IOException
	{
		primaryStage.setTitle("Sonnet");

		// This is how you know how much screen you can write to.
		Screen screen = Screen.getPrimary();
		Rectangle2D bounds = screen.getVisualBounds();
		System.out.println(bounds);

		primaryStage.setFullScreen(true);
		//primaryStage.setMaximized(true);
		primaryStage.setWidth( bounds.getWidth() );
		primaryStage.setHeight( bounds.getHeight() );

		/*Dimension dimension = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight() );
		dimension.width = (int)bounds.getWidth();
		dimension.height = (int)bounds.getHeight() + 40;
		Dimension Dim = dimension;//*/

		double fRateDivisor = 40;//11 * 1904 For Scrolling Text//Testing: 4;//10;//124;//2;//10;//22<- 444 HERE HERE HERE DETERMINES FRAME RATE AND RAINBOW MOVEMENT RATE For Rainbow Lights

		//FXMLLoader loader = new FXMLLoader(Sonnet.class.getResource("main.fxml"));

		StackPane stackPane[] = new StackPane[(int)(fRateDivisor + 1)];
		stackPane[0] = new StackPane();
		stackPane[0].setPrefSize( bounds.getWidth(), bounds.getHeight() + 40 );//stackPane.setPrefSize(1920, 1080);//stackPane.setPrefSize(960, 540);
		//Image image = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");

		Scene scene[] = new Scene[(int)(fRateDivisor + 1)];
		ProgressBar progressBar = new ProgressBar();
		Button goButton = new Button("Go!");
		Label stateLabel = new Label();
		TextField addressBar = new TextField();
		//addressBar.setText("http://www.google.com");
		//addressBar.setText("http://www.pixies.zone/PixiesTest.html");
		WebView browser = new WebView();
		browser.setPrefSize( bounds.getWidth(), bounds.getHeight() + 40 );
		WebEngine webEngine = browser.getEngine();
		//webEngine.load("https://news.google.com/news/?ned=us&hl=en&gl=US");
		//webEngine.load("http://www.pixies.zone/PixiesTest%20-%20Copy.html");
		webEngine.load("file:///C:/Users/AllAV/Desktop/FWA%20Website/pixies.zone/PixiesTest%20-%20Copy%20(2).html");//"file:///C:/Test.html");//"file:///C:/Users/AllAV/Desktop/FWA%20Website/pixies.zone/PixiesTest%20-%20Copy.html"
		//webEngine.load("http://www.pixies.zone/PixiesTest.html");
		//WritableImage origionalTextPicture = new WritableImage( dimension.width, dimension.height );
		Image origionalBasisImage = new Image("http://www.nanofirm.org/magielite.com/Pictures/SciMagOrderMagiEliteFullHD.png");
		JFileChooser jFileChooser = new JFileChooser();
		String path = "C:\\TestVideo.mp4", text = "Sky.Netarianism";//"C:\\TestImage.png"//"C:\\TestVideo.mp4"//"C:\\TEMP_Sonnet.mp4";
		File selectedFile = new File (path);
		File javaScriptFile = new File ("C:/Users/AllAV/Desktop/FWA Website/pixies.zone/scrollContinuously444.js");
		jFileChooser.setSelectedFile(selectedFile);
		int returnValue = jFileChooser.showSaveDialog(null);
		if (returnValue == JFileChooser.APPROVE_OPTION)
		{
			selectedFile = jFileChooser.getSelectedFile();
			System.out.println(selectedFile.getName());
			System.out.println(selectedFile.getPath());
		}
		SequenceEncoder enc = new SequenceEncoder(selectedFile);
		//try { SequenceEncoder enc = new SequenceEncoder(secondFile); }
		//catch (IOException e) {	throw new RuntimeException(e); }//*/
		System.out.println("Got To Worker");
		Worker<Void> worker = webEngine.getLoadWorker();
		worker.stateProperty().addListener(new ChangeListener<State>() {
			@Override
			public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {System.out.println("Got To Worker Test");
			stateLabel.setText("Loading state: " + newValue.toString());
			if (newValue == Worker.State.SUCCEEDED) {
				RainbowSystem(primaryStage, origionalBasisImage, browser, stackPane, scene, screen, fRateDivisor, stateLabel, jFileChooser.getSelectedFile(), javaScriptFile, enc);
				/*scene[(int)fRateDivisor].setOnKeyReleased(new EventHandler<KeyEvent>()
				{
					@Override
					public void handle(KeyEvent event)
					{
						if ( event.isAltDown() == true)
						{
							switch (event.getCode())
							{
							case ENTER: primaryStage.setFullScreen(!primaryStage.isFullScreen()); break;
							}
						}
					}
				});//*/
				/*try { RainbowSystem(primaryStage, browser, stackPane, scene, screen, fRateDivisor, stateLabel, selectedFile); }//enc,
				catch (IOException e) {	throw new RuntimeException(e); //*/}
			}
		});



		primaryStage.setScene(scene[0]);
		primaryStage.setFullScreen(true);
		primaryStage.show();

		progressBar.progressProperty().bind(worker.progressProperty());



		/*goButton.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				String url = addressBar.getText();
				// Load the page.
				webEngine.load(url);
			}
		});//*/
	}





	public static void RainbowSystem (Stage secondaryStage, Image basisImage, WebView secondBrowser, StackPane secondStackPane[], Scene secondScene[], Screen secondScreen,
			double secondFRateDivisor, Label SecondStateLabel, File secondFile, File secondJavaScriptFile, SequenceEncoder secondEnc)//SequenceEncoder secondEnc,
	{
		System.out.println("Got In Worker");
		// This is how you know how much screen you can write to.
		/*Screen screen = Screen.getPrimary();
			Rectangle2D bounds = screen.getVisualBounds();
			System.out.println(bounds);

			secondaryStage.setFullScreen(true);
			Dimension dimension = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight() );
			dimension.width = (int)bounds.getWidth();
			dimension.height = (int)bounds.getHeight() + 40;
			Dimension Dim = dimension;*/

		/*try ( PrintWriter out0 = new PrintWriter(secondJavaScriptFile.getPath() ) )
		{
			out0.println("function scrollContinuously( timeInterval )\r\n" + 
				"{\r\n" + 
				"	timeInterval = 444;\r\n" + 
				"	window.setInterval( scrollWin, timeInterval );\r\n" + 
				"}\r\n" + 
				"function scrollWin()\r\n" + 
				"{\r\n" + 
				"    window.scrollBy( 0, 0 );\r\n" + 
				"}");
			out0.close();
		}// */
		
		/*try (Writer writer = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(secondJavaScriptFile), "utf-8"))) {
	   writer.write( "Can Write A Line" );/*"function scrollContinuously( timeInterval )\r\n" + 
				"{\r\n" + 
				"	timeInterval = 444;\r\n" + 
				"	window.setInterval( scrollWin, timeInterval );\r\n" + 
				"}\r\n" + 
				"function scrollWin()\r\n" + 
				"{\r\n" + 
				"    window.scrollBy( 0, 0 );\r\n" + 
				"}");// /
		}
		catch(IOException ie) { ie.printStackTrace(); }// */		
		
		PrintWriter writer = null;
		try {System.out.println("Got In JS Writer");
			writer = new PrintWriter( "C:/Users/AllAV/Desktop/FWA Website/pixies.zone/scrollContinuously444.js" );//, "UTF-8");
			writer.println("function scrollContinuously( timeInterval )\r\n" +
				"{\r\n" + 
				"	timeInterval = 444;\r\n" + 
				"	window.setInterval( scrollWin, timeInterval );\r\n" + 
				"}\r\n" + 
				"function scrollWin()\r\n" + 
				"{\r\n" + 
				"    window.scrollBy( 0, 0 );\r\n" + 
				"}");// */
			writer.close();
		}
		catch(IOException ie2) { ie2.printStackTrace(); }
		
		System.out.println("Got Past JS Writer");
		
		Dimension Dim = new Dimension();
		Dim.width = (int)secondaryStage.getWidth();
		Dim.height = (int)secondaryStage.getHeight();// + 40;

		secondaryStage.setTitle(secondBrowser.getEngine().getLocation());
		SecondStateLabel.setText("Finish!");

		//SequenceEncoder enc = new SequenceEncoder(secondFile);
		//try { SequenceEncoder enc = new SequenceEncoder(secondFile); }
		//catch (IOException e) {	throw new RuntimeException(e); }//*/


		WritableImage origionalTextPicture = new WritableImage( Dim.width, Dim.height );
		WritableImage bufferPicure = new WritableImage( Dim.width, Dim.height );
		//origionalTextPicture = secondBrowser.snapshot(null, bufferPicure);
		//WritableImage origionalTextPicture = new WritableImage( Dim.width, Dim.height ), bufferPicure = new WritableImage( Dim.width, Dim.height );
		/*//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//browser.snapshot(sP, origionalTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
			//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Test.png");//browser.snapshot(sP, origionalTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
			stackPane[0].getChildren().add(browser);

			scene[0] = new Scene(stackPane[0]);
			secondaryStage.setScene(scene[0]);

			secondaryStage.setFullScreen(true);
			secondaryStage.show();

			//boolean encFinished = false;
			//while (encFinished =  false)
				//if ( stateLabel.getText() == "Finish!")//secondaryStage.isShowing() && secondaryStage.isFullScreen() )
				//{*/
		SnapshotParameters sP = new SnapshotParameters();
		sP.setViewport(secondScreen.getBounds());
		secondStackPane[0] = new StackPane();
		secondStackPane[0].getChildren().add(secondBrowser);
		secondScene[0] = secondStackPane[0].getScene();
		secondScene[0] = new Scene(secondStackPane[0]);

		double xSlider = 0; //MUST START OUT AS 0 Or Else Video Won't Produce Or Potentially Scroll At All!
		Dimension HalfedDim = new Dimension();
		HalfedDim.width = Math.round( ( Dim.width + 1 ) / 2 - 1 );
		HalfedDim.height = Math.round( ( Dim.height + 1 ) / 2 - 1 );
		double radialDistance = Math.pow(Math.pow(HalfedDim.width + 1, 2) + Math.pow(HalfedDim.height + 1, 2), 0.5);
		double fullAngle = Math.PI * radialDistance;
		secondScene[(int)(secondFRateDivisor * xSlider/fullAngle)].setOnKeyReleased(new EventHandler<KeyEvent>()
		{
			@Override
			public void handle(KeyEvent event)
			{
				if ( event.isAltDown() == true)
				{
					switch (event.getCode())
					{
					case ENTER: secondaryStage.setFullScreen(!secondaryStage.isFullScreen()); break;
					}
				}
			}
		});//*/

		Image origionalBrowserImage = secondBrowser.snapshot(sP, origionalTextPicture);
		//origionalTextPicture = secondBrowser.snapshot(sP, origionalTextPicture);
		//Image origionalBrowserImage = secondScene[0].snapshot(origionalTextPicture);
		origionalBrowserImage = secondScene[0].snapshot(origionalTextPicture);
		origionalBrowserImage = secondStackPane[0].getScene().snapshot(bufferPicure);
		secondaryStage.setScene(secondScene[0]);
		secondaryStage.setFullScreen(true);
		secondaryStage.show();
		System.out.println("Past Stage Being Shown");

		//VBox root = new VBox();
		//root.getChildren().addAll(addressBar, goButton, stateLabel, progressBar, browser);
		//secondScene[0] = new Scene(secondStackPane[0]);
		//secondaryStage.setScene(secondScene[0]);



		//secondaryStage.setFullScreen(true);
		//secondaryStage.show();

		//WritableImage origionalTextPicture = new WritableImage( Dim.width, Dim.height );
		//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//browser.snapshot(sP, origionalTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
		//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Test.png");//browser.snapshot(sP, origionalTextPicture);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");//
		//secondStackPane[0].getChildren().add(browser);

		//secondScene[0] = new Scene(secondStackPane[0]);
		//secondaryStage.setScene(secondScene[0]);

		//secondaryStage.setFullScreen(true);
		//secondaryStage.show();
		//JUST THIS DISPLAYS BROWSER!!!!!






		//origionalTextPicture = secondScene[0].snapshot(null);

		//Image origionalBrowserImage = secondScene[0].snapshot(null);//browser.snapshot(sP, origionalTextPicture);
		//Image origionalBrowserImage = new Image("http://www.nanofirm.org/scimagorder.com/Pictures/FatLevels.png");

		///TEST
		origionalBrowserImage = secondBrowser.snapshot(sP, bufferPicure);//new Image("http://www.nanofirm.org/scimagorder.com/Pictures/Pixies%20Text.png");
		///TEST

		//secondStackPane[(int)(fRateDivisor * xSlider/fullAngle) + 1].getChildren().add(browser);

		PixelReader origionalpr = origionalBrowserImage.getPixelReader();
		origionalpr = secondStackPane[0].getScene().snapshot(bufferPicure).getPixelReader();
		PixelWriter origionalpw = bufferPicure.getPixelWriter();
		ImageView origionalImageView = new ImageView();
		origionalImageView.setImage(origionalBrowserImage);






		//secondScene[0].setRoot(browser);

		//secondStackPane[0].getChildren().add(origionalImageView);
		//secondStackPane[0].getChildren().add(browser);


		/*File tempFile;
//WebDriver driver=new FirefoxDriver();

// Maximize the window
driver.manage().window().maximize();

// Pass the url
driver.get("http://www.pixies.zone/PixiesTest.html");

// Take screenshot and store as a file format
File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {// now copy the  screenshot to desired location using copyFile //method
	FileUtils.copyFile(src, new File("C:/TempImage.png"));
}

catch (IOException e)
{
	System.out.println(e.getMessage());

}// */
		PixelReader basispr = basisImage.getPixelReader();

		WritableImage writableImage = origionalTextPicture;
		PixelReader pr = writableImage.getPixelReader();
		PixelWriter pw = writableImage.getPixelWriter();
		ImageView imageView = new ImageView();
		imageView.setImage(writableImage);

		ColorSlider black = new ColorSlider( new double[]{0,0,0} );

		ColorSlider color = black;

		ColorSlider white = new ColorSlider( new double[]{255,255,255} );
		ColorSlider skyblue = new ColorSlider( new double[]{134,206,249} );
		ColorSlider oxylblue = new ColorSlider( new double[]{0,255,255} );
		ColorSlider pink = new ColorSlider( new double[]{255,64,143} );
		ColorSlider blue = new ColorSlider( new double[]{0,0,192} );
		ColorSlider red = new ColorSlider( new double[]{193,0,0} );
		ColorSlider purple = new ColorSlider( new double[]{122,0,178} );
		ColorSlider orange = new ColorSlider( new double[]{255,134,0} );
		ColorSlider green = new ColorSlider( new double[]{0,133,50} );
		ColorSlider yellow = new ColorSlider( new double[]{246,252,15} );
		ColorSlider teal = new ColorSlider( new double[]{3,224,149} );
		ColorSlider bronze = new ColorSlider( new double[]{152,123,46} );
		ColorSlider silver = new ColorSlider( new double[]{193,192,192} );
		ColorSlider gold = new ColorSlider( new double[]{205,191,44} );
		ColorSlider lime = new ColorSlider( new double[]{126,193,33} );
		ColorSlider brown = new ColorSlider( new double[]{131,103,71} );

		int oxylBlueNum = (int)(255 * 16777216) + (int)(0 * 65536) + (int)(246 * 256) + 255;
		int oxylBlue0FFNum = (int)(255 * 16777216) + (int)(0 * 65536) + (int)(255 * 256) + 255;
		int skyBlueNum = (int)(255 * 16777216) + (int)(135 * 65536) + (int)(206 * 256) + 250;
		int magentaNum = (int)(255 * 16777216) + (int)(255 * 65536) + (int)(0 * 256) + 255;
		int halfGreyNum = (int)(255 * 16777216) + (int)(127 * 65536) + (int)(127 * 256) + 127;
		int pinkNum = (int)(255 * 16777216) + (int)(255 * 65536) + (int)(64 * 256) + 143;
		int maroonNum = (int)(255 * 16777216) + (int)(167 * 65536) + (int)(0 * 256) + 118;
		int shitBrownNum = (int)(255 * 16777216) + (int)(110 * 65536) + (int)(82 * 256) + 48;
		int simpleBlueNum = (int)(255 * 16777216) + (int)(0 * 65536) + (int)(0 * 256) + 255;
		int neonGreenNum = (int)(255 * 16777216) + (int)(0 * 65536) + (int)(255 * 256) + 0;
		int webBlackNum = (int)(255 * 16777216) + (int)(0 * 65536) + (int)(0 * 256) + 0;
		int whiteNum = (int)(255 * 16777216) + (int)(255 * 65536) + (int)(255 * 256) + 255;

		int white1Num = (int)(255 * 16777216) + (int)(254 * 65536) + (int)(254 * 256) + 254;
		int white2Num = (int)(255 * 16777216) + (int)(253 * 65536) + (int)(253 * 256) + 253;
		int white3Num = (int)(255 * 16777216) + (int)(252 * 65536) + (int)(252 * 256) + 252;
		int white4Num = (int)(255 * 16777216) + (int)(251 * 65536) + (int)(251 * 256) + 251;
		int black6Num = (int)(255 * 16777216) + (int)(6 * 65536) + (int)(6 * 256) + 6;

		int numberOfColorsInTheRainbow = 7;//asdf Always Worry About This!

		//Dimension HalfedDim = new Dimension();
		//HalfedDim.width = Math.round( ( Dim.width + 1 ) / 2 - 1 );
		//HalfedDim.height = Math.round( ( Dim.height + 1 ) / 2 - 1 );
		int x = 0, y = 0, xMinusxSlider = 0, yMinusxSlider = 0, ySlider = 0, yMinusySlider = 0, cyMy = 0,  b = 0, xSliderFactor = 1, xSliderBackAndFourth = 1, fixedOfabcd = 4, numOfabcd = 4, colorIntervalDivisor = 1, aCounter = 0, bCounter = 0, cCounter = 0;//cxMx Corrected xMinusSlider for determining color
		double a = 0, colorIntervalForWholeScreen = Dim.width / ( numberOfColorsInTheRainbow - 1 ), numberOfClockHandsForRainbow = 7, numberOfColorsForOrderOfMagi = 3, numberOfClockHandsForOrderOfMagi = 16, abcd = 0, abc = 0, rCheck = 0, aAngle = 0, bAngle = 0, newx = 0, newy = 0, abc2 = 0, aIncrementAngle = 0, bIncrementAngle = 0, aTan = 0, cxMx = 0;
		boolean fullScreened = true, TrispectralRainbow = false, someTargetColorHit = false, greenBlueGreenUsed = false, someTargetColorInTheCenterHit = false, otherBrowserColorHit = false;
		if (TrispectralRainbow == true)
			colorIntervalForWholeScreen = colorIntervalForWholeScreen / 3;//For Trispectral Rainbow.
		double colorDisplacement = 0;//For Rainbow Disk And 0 Rainbow Clock
		//double radialDistance = Math.pow(Math.pow(HalfedDim.width + 1, 2) + Math.pow(HalfedDim.height + 1, 2), 0.5);
		double angle1 = 0, angle2 = 0, angle3 = 0, angle4 = 0, aAngleCheck = 0;
		double radius = 0;
		double angle = 0;
		//double fullAngle = Math.PI * radialDistance;
		double fullScrollCycle = fullAngle / 10 / 444 * secondFRateDivisor;//1904 Scroll Height In Pixels //444 Speed When secondFRateDivisor
		double interval = fullScrollCycle / secondFRateDivisor;// / 10 For Rainbow Spotlight Last Division Determines The Frame Rate
		int scrollOnePixelCounter = 0;
		int scrollDownValue = 0;
		colorIntervalForWholeScreen = fullAngle / ( numberOfColorsInTheRainbow - 1 );//For Rainbow Clock And Spiral
		///double interval = radialDistance * 2 * Math.PI / 1444;//1444 Instead Of 14 Gets The Frame Rate To Have Contiguous Motion For Rainbow Clock
		//double fullAngle = 2 * Math.PI * radialDistance;//For Rainbow Clock
		//colorIntervalForWholeScreen = fullAngle / ( numberOfColorsInTheRainbow - 1 ) / numberOfClockHands;//For Rainbow Clock
		//for (xSlider = (int)Math.round(colorDisplacement) + radialDistance * 2 * Math.PI / numberOfClockHands / 2; xSlider < 1.5 * ( radialDistance * 2 * Math.PI / numberOfClockHands ); xSlider++)// < For Rainbow Clock, xSlider = (int)Math.round(colorDisplacement); For Rings -144 Use cy And < HalfedDim.height Instead of Dim.height For Circular Rainbow Use Dim.width < For Rainbow Slider And Fractal //Start At -144 For Videos And Pictures
		System.out.println("Got To Main Program Loop");
		final double chrysanthemumRadius = 60;
		final double chrysanthemumInnerRadius = 9;
		final double chrysanthemumYDisplacement = 25;
		final double chrysanthemumNumberOfPedals = 16;
		double coreVariable = 0, angleVariable = 0, aVariable = 0, radiusVariable = 0, fullCycleVariable = 0, colorDisplacementVariable = 0, colorIntervalVariable = 0, speedIncreaseFactor = numberOfColorsInTheRainbow, speedDecreaseFactor = 1 / numberOfColorsInTheRainbow;
		double radialVariableDistance = 0;//Hypnosis Spiral
		double diskColorInterval = Dim.width / ( numberOfColorsInTheRainbow - 1 );//Rainbow Disk
		double ringColorInterval = diskColorInterval * 0.175979734764;//Rainbow Ring
		double ringcolorDisplacement = HalfedDim.height * (1 - 0.175979734764);
		System.out.println("Got Before Main Display Loop");
		while ( xSlider < fullScrollCycle )//For MagiElite: fullAngle / 10)//for (xSlider = 0; xSlider <= 0.175979734764 * cy; xSlider++)
		{//0.175979734764 *
			if ( secondaryStage.isFullScreen() == false )
			{
				if ( fullScreened != secondaryStage.isFullScreen() )
				{
					secondaryStage.setFullScreen(true);
					Dim.width = 600;
					Dim.height = 400;
				}
				else 
				{
					Dim.width = (int)secondaryStage.getWidth();
					Dim.height = (int)secondaryStage.getHeight() + 80;//40;
				}
				sP.setViewport( new Rectangle2D( (double)Dim.width, (double)Dim.height, 0, 0 ) );
				origionalBrowserImage = secondBrowser.snapshot(sP, origionalTextPicture);
				//Image origionalBrowserImage = secondScene[(int)(secondFRateDivisor * xSlider/fullAngle)].snapshot(origionalTextPicture);
				origionalBrowserImage = secondScene[(int)(secondFRateDivisor * xSlider/fullAngle)].snapshot(origionalTextPicture);
				origionalBrowserImage = secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle)].getScene().snapshot(bufferPicure);
				secondaryStage.setScene(secondScene[(int)(secondFRateDivisor * xSlider/fullAngle)]);
				secondaryStage.setFullScreen(true);
				secondaryStage.show();//*/

				basispr = basisImage.getPixelReader();

				origionalpr = origionalBrowserImage.getPixelReader();
				origionalpr = secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle)].getScene().snapshot(bufferPicure).getPixelReader();
				origionalpw = bufferPicure.getPixelWriter();
				origionalImageView = new ImageView();
				origionalImageView.setImage(origionalBrowserImage);

			}
			else if ( fullScreened != secondaryStage.isFullScreen() )
			{
				secondaryStage.setFullScreen(true);
				secondaryStage.setWidth(secondScreen.getBounds().getWidth());
				secondaryStage.setHeight(secondScreen.getBounds().getHeight());
				Dim.width = (int)secondaryStage.getWidth();
				Dim.height = (int)secondaryStage.getHeight() + 40;

				sP.setViewport( new Rectangle2D( (double)Dim.width, (double)Dim.height, 0, 0 ) );
				origionalBrowserImage = secondBrowser.snapshot(sP, origionalTextPicture);
				//Image origionalBrowserImage = secondScene[(int)(secondFRateDivisor * xSlider/fullAngle)].snapshot(origionalTextPicture);
				origionalBrowserImage = secondScene[(int)(secondFRateDivisor * xSlider/fullAngle)].snapshot(origionalTextPicture);
				origionalBrowserImage = secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle)].getScene().snapshot(bufferPicure);
				secondaryStage.setScene(secondScene[(int)(secondFRateDivisor * xSlider/fullAngle)]);
				secondaryStage.setFullScreen(true);
				secondaryStage.show();//*/

				basispr = basisImage.getPixelReader();

				origionalpr = origionalBrowserImage.getPixelReader();
				origionalpr = secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle)].getScene().snapshot(bufferPicure).getPixelReader();
				origionalpw = bufferPicure.getPixelWriter();
				origionalImageView = new ImageView();
				origionalImageView.setImage(origionalBrowserImage);
			}




			/*Dim.width = (int)secondaryStage.getWidth();
				Dim.height = (int)secondaryStage.getHeight() + 40;
				Dim = Dim;//*/
			//secondStackPane[(int)(secondFRateDivisor * (xSlider - interval)/fullAngle) + 1].getChildren().add(browser);
			//origionalpr = secondStackPane[(int)(secondFRateDivisor * (xSlider - interval)/fullAngle) + 1].getScene().snapshot(bufferPicure).getPixelReader();
			//Dim = f.getSize();//Dim = f.getContentPane().getSize();
			HalfedDim.width = Math.round( ( Dim.width + 1 ) / 2 - 1 );
			HalfedDim.height = Math.round( ( Dim.height + 1 ) / 2 - 1 );
			radialDistance = Math.pow(Math.pow(HalfedDim.width + 1, 2) + Math.pow(HalfedDim.height + 1, 2), 0.5);
			rCheck = HalfedDim.height / fixedOfabcd;
			numOfabcd = (int)Math.ceil(radialDistance / HalfedDim.height);
			//double[] angle = new double[numOfabcd], abcdefg = new double[numOfabcd];
			colorDisplacement = 0;//For Rainbow Disk
			for (x = 0; x < Dim.width; x++)//Comment Out Here For Circular Rainbow
			{//Comment Out Here For Circular Rainbow
				for (y = 0; y < Dim.height; y++)
				{// coreVariable // angleVariable // aVariable // radiusVariable // fullCycleVariable // colorDisplacementVariable // colorIntervalVariable XXXXXX // speedIncreaseFactor // speedDecreaseFactor
					someTargetColorHit = true;
					someTargetColorInTheCenterHit = false;
					greenBlueGreenUsed = false;
					otherBrowserColorHit = false;
					if ( origionalpr.getArgb( x, y ) != magentaNum && origionalpr.getArgb( x, y ) != whiteNum)
					{
						otherBrowserColorHit = true;
					}
					else
						if ( Math.pow(Math.pow(x - HalfedDim.width + 1, 2) + Math.pow( y  - HalfedDim.height + 1 + chrysanthemumYDisplacement, 2), 0.5) <= 64 )
						{//902 //1019
							someTargetColorInTheCenterHit = true;
							if ( basispr.getArgb( x, y ) == black6Num )
							{
								coreVariable = chrysanthemumRadius - Math.pow(Math.pow(x - HalfedDim.width + 1, 2) + Math.pow( y - HalfedDim.height + 1 + chrysanthemumYDisplacement, 2), 0.5) + 6 * 0.175979734764 * chrysanthemumRadius * xSlider / ( fullAngle / 10 ) ;
								while ( coreVariable < 0.175979734764 * chrysanthemumRadius)
									coreVariable = coreVariable + 0.175979734764 * chrysanthemumRadius;
								while ( coreVariable > 0.175979734764 * chrysanthemumRadius)
									coreVariable = coreVariable - 0.175979734764 * chrysanthemumRadius;
								colorIntervalVariable = 0.175979734764 * chrysanthemumRadius / ( numberOfColorsInTheRainbow - 1 );
							}
							else
								if ( basispr.getArgb( x, y ) == white1Num )
								{
									radialVariableDistance = Math.pow(Math.pow(x - HalfedDim.width + 1, 2) + Math.pow( y - HalfedDim.height + 1 + chrysanthemumYDisplacement, 2), 0.5);//Comment Out For  Ghetto Many Rainbow Clocks
									angleVariable =  chrysanthemumRadius * ( ( - Math.atan2( (x - HalfedDim.width + 1) , (y - HalfedDim.height + 1 + chrysanthemumYDisplacement) ) + Math.PI ) - 6 * Math.PI * xSlider / ( fullAngle / 10 ) );//Use For Rainbow Spiral Multiply radialDistance By 10 To Increase The Number Of Spirals
									radiusVariable = chrysanthemumRadius * ( radialVariableDistance * 24.6 + colorDisplacement + angleVariable);//radialVariableDistance + colorDisplacement + angle;//Remove + angle And Add xSlider To Make Rainbow Clock
									while ( radiusVariable < colorDisplacement)//For Rainbow Ring
										radiusVariable = radiusVariable + 2 * Math.PI * chrysanthemumRadius - colorDisplacement;//BAD COMMENT: For Rainbow Ring Take Out - 38
									while ( radiusVariable > 2 * Math.PI * chrysanthemumRadius )
										radiusVariable = radiusVariable - 2 * Math.PI * chrysanthemumRadius - colorDisplacement;
									colorIntervalVariable = 2 * Math.PI * chrysanthemumRadius / ( numberOfColorsInTheRainbow - 1 );
									coreVariable = radiusVariable;
								}
								else
									if ( basispr.getArgb( x, y ) == white2Num )
									{
										coreVariable = x - 902 - chrysanthemumRadius * 2 * xSlider / ( fullAngle / 10 );
										while (coreVariable < 0)
											coreVariable = coreVariable + chrysanthemumRadius * 2;
										while (coreVariable > chrysanthemumRadius * 2)
											coreVariable = coreVariable - chrysanthemumRadius * 2;
										colorIntervalVariable = chrysanthemumRadius * 2 / (numberOfColorsInTheRainbow - 1 );
									}
									else
										if ( basispr.getArgb( x, y ) == white3Num )
										{
											angleVariable = - chrysanthemumRadius *  2 * Math.PI * ( ( Math.atan2( (x - HalfedDim.width + 1) , ( y - HalfedDim.height + 1 + chrysanthemumYDisplacement ) ) + Math.PI ) + xSlider / ( ( chrysanthemumNumberOfPedals - 1 ) * fullAngle / 10 ) ) ;
											while (angleVariable < 0)
												angleVariable = angleVariable + chrysanthemumRadius / ( chrysanthemumNumberOfPedals - 1);
											while (angleVariable > chrysanthemumRadius / (chrysanthemumNumberOfPedals - 1) )
												angleVariable = angleVariable - chrysanthemumRadius / ( chrysanthemumNumberOfPedals - 1);
											coreVariable = angleVariable;
											colorIntervalVariable = chrysanthemumRadius / ( ( numberOfClockHandsForRainbow - 1 ) * ( chrysanthemumNumberOfPedals - 1) );
										}
										else
											if ( basispr.getArgb( x, y ) == white4Num )
											{
												radialVariableDistance = Math.pow(Math.pow(x - HalfedDim.width + 1, 2) + Math.pow( y - HalfedDim.height + 1 + chrysanthemumYDisplacement, 2), 0.5);//Comment Out For  Ghetto Many Rainbow Clocks
												angleVariable = ( ( - Math.atan2( (x - HalfedDim.width + 1) , (y - HalfedDim.height + 1 + chrysanthemumYDisplacement) ) + Math.PI ) - 6 * Math.PI * xSlider / ( fullAngle / 10 ) ) * 10 * chrysanthemumRadius;//Use For Rainbow Spiral Multiply radialDistance By 10 To Increase The Number Of Spirals
												radiusVariable = ( radialVariableDistance * 24.6 + colorDisplacement + angleVariable ) / ( 2 * chrysanthemumRadius);//radialVariableDistance + colorDisplacement + angle;//Remove + angle And Add xSlider To Make Rainbow Clock
												while ( radiusVariable < colorDisplacement)//For Rainbow Ring
													radiusVariable = radiusVariable + 2 * chrysanthemumRadius * Math.PI - colorDisplacement;//BAD COMMENT: For Rainbow Ring Take Out - 38
												while ( radiusVariable > 2 * chrysanthemumRadius * Math.PI )
													radiusVariable = 2 * chrysanthemumRadius * Math.PI - colorDisplacement;
												colorIntervalVariable = 2 * chrysanthemumRadius * Math.PI / ( numberOfColorsInTheRainbow - 1 );
												coreVariable = radiusVariable;// / ( Dim.height / 64);
											}
											else
												if ( basispr.getArgb( x, y ) == simpleBlueNum )
												{//951 To 969
													coreVariable = chrysanthemumInnerRadius - Math.pow(Math.pow(x - HalfedDim.width, 2) + Math.pow( y - HalfedDim.height + chrysanthemumYDisplacement, 2), 0.5) + 88 * chrysanthemumInnerRadius * xSlider / ( fullAngle / 10 ) ;
													while ( coreVariable < chrysanthemumInnerRadius)
														coreVariable = coreVariable + chrysanthemumInnerRadius;
													while ( coreVariable > chrysanthemumInnerRadius)
														coreVariable = coreVariable - chrysanthemumInnerRadius;
													colorIntervalVariable = chrysanthemumInnerRadius / ( numberOfColorsInTheRainbow - 1 );
												}
												else
													someTargetColorInTheCenterHit = false;
						}
					if ( someTargetColorInTheCenterHit == false )
						if ( basispr.getArgb( x, y ) == oxylBlueNum)
						{
							angleVariable = Math.atan2( (x - HalfedDim.width + 1) , (y - Dim.height * 4 / 3 + 1 ) );// For Rising Sun + 1
							aVariable = ( angleVariable * /*Math.cos( angle ) * Math.sin( angle ) * Math.pow(radialVariableDistance, 1)*/ Math.tan( angleVariable ) /*+ Math.PI*/ )  * radialDistance / 4.46783504 + xSlider;// + Or - xSlider Determines Which Direction It Moves //For Infinite Number Theorem Good a = ( angle * /*Math.cos( angle ) * Math.sin( angle ) * Math.pow(radialVariableDistance, 1)*/ Math.tan( angle ) + Math.PI )  * radialDistance / 4.46783504 - xSlider;  //a = ( angle /*Math.cos( angle ) * Math.sin( angle ) * Math.pow(radialVariableDistance, 1)*/ Math.tan( angle ) + Math.PI )  * radialDistance / 4.46783504 - xSlider;//Use For Rainbow Spiral Multiply radialDistance By 10 To Increase The Number Of Spirals //Use This: "a = ( - angle + Math.PI ) * radialDistance;" Line For Rainbow Clock //a = ( - angle * Math.tan( angle ) + Math.PI ) * radialDistance - xSlider; For Infinite Number Theorem //a = ( - angle * Math.cos( angle ) * Math.sin( angle ) * Math.pow(radialVariableDistance, 2) + Math.PI ) * radialDistance - xSlider; */
							radiusVariable = aVariable * 10;
							// *///For Old Infinite Number Theorem Use Above
							//radius = a * 10;//For Rainbow Spiral And Clock
							//}
							while ( radiusVariable < colorDisplacementVariable)//For Rainbow Ring
								radiusVariable = radiusVariable + fullAngle - colorDisplacementVariable;//BAD COMMENT: For Rainbow Ring Take Out - 38
							while ( radiusVariable > fullAngle )//radius > fullAngle For Non Infinite Number Theorem
								radiusVariable = radiusVariable - fullAngle - colorDisplacementVariable; //radius = radius - fullAngle; For Non Infinite Number Theorem //For Rainbow Clock Comment Out To Here. Here -- */
							colorIntervalVariable = colorIntervalForWholeScreen;
							coreVariable = radiusVariable;
						}
						else
							if ( basispr.getArgb( x, y ) == skyBlueNum)
							{
								radialVariableDistance = Math.pow(Math.pow(x - HalfedDim.width + 1, 2) + Math.pow( y - HalfedDim.height + 1, 2), 0.5);//Comment Out For  Ghetto Many Rainbow Clocks
								angleVariable = ( ( - Math.atan2( (x - HalfedDim.width + 1) , (y - HalfedDim.height + 1 ) ) + Math.PI ) - 6 * Math.PI * xSlider / ( fullAngle / 10 ) ) * radialDistance;//Use For Rainbow Spiral Multiply radialDistance By 10 To Increase The Number Of Spirals
								radiusVariable = radialVariableDistance * 24.6 + colorDisplacement + angleVariable;//radialVariableDistance + colorDisplacement + angle;//Remove + angle And Add xSlider To Make Rainbow Clock
								while ( radiusVariable < colorDisplacement)//For Rainbow Ring
									radiusVariable = radiusVariable + fullAngle - colorDisplacement;//BAD COMMENT: For Rainbow Ring Take Out - 38
								while ( radiusVariable > fullAngle )
									radiusVariable = radiusVariable - fullAngle - colorDisplacement;
								colorIntervalVariable = fullAngle / ( numberOfColorsInTheRainbow - 1 );
								coreVariable = radiusVariable;						
							}
							else
								if ( basispr.getArgb( x, y ) == magentaNum)
								{
									coreVariable = HalfedDim.height - Math.pow(Math.pow(x - HalfedDim.width + 1, 2) + Math.pow( y - HalfedDim.height + 1, 2), 0.5) + 6 * 0.175979734764 * xSlider * HalfedDim.height / ( fullAngle / 10 ) ;
									while ( coreVariable < 0.175979734764 * HalfedDim.height)
										coreVariable = coreVariable + 0.175979734764 * HalfedDim.height;
									while ( coreVariable > 0.175979734764 * HalfedDim.height)
										coreVariable = coreVariable - 0.175979734764 * HalfedDim.height;
									colorIntervalVariable = 0.175979734764 * HalfedDim.height / ( numberOfColorsInTheRainbow - 1 );
								}
								else
									if ( basispr.getArgb( x, y ) == neonGreenNum )
									{
										angleVariable = radialDistance * ( ( Math.atan2( (x - HalfedDim.width + 1) , (y - HalfedDim.height + 1 ) ) + Math.PI ) + 2 * Math.PI * xSlider / ( fullAngle / 10 ) );
										while (angleVariable < 0)
											angleVariable = angleVariable + fullAngle * 2;
										while (angleVariable > fullAngle * 2)
											angleVariable = angleVariable - fullAngle * 2;
										coreVariable = angleVariable;
										colorIntervalVariable = ( 2 * fullAngle ) / ( numberOfClockHandsForRainbow - 1 );
										//angle = 0;//Testing Purposes Only.
									}
									else
										if ( basispr.getArgb( x, y ) == halfGreyNum )
										{
											angleVariable = - radialDistance * ( ( Math.atan2( (x - HalfedDim.width + 1) , (y - HalfedDim.height + 1 ) ) + Math.PI ) - 2 * Math.PI * xSlider / ( fullAngle / 10 ) );
											while (angleVariable < 0)
												angleVariable = angleVariable + fullAngle * 2;
											while (angleVariable > fullAngle * 2)
												angleVariable = angleVariable - fullAngle * 2;
											coreVariable = angleVariable;
											colorIntervalVariable = ( 2 * fullAngle ) / ( numberOfClockHandsForRainbow - 1 );
											//angle = 0;//Testing Purposes Only.
										}
										else
											if ( basispr.getArgb( x, y ) == maroonNum )//neonGreenNum)
											{
												angleVariable = - radialDistance * ( ( Math.atan2( (x - HalfedDim.width + 1) , (y - HalfedDim.height + 1 ) ) + Math.PI ) + 2 * Math.PI * xSlider / ( (numberOfClockHandsForOrderOfMagi - 1) * fullAngle / 10 ) );
												while (angleVariable < 0)
													angleVariable = angleVariable + fullAngle * 2 / ( numberOfClockHandsForOrderOfMagi - 1);
												while (angleVariable > fullAngle * 2 / ( numberOfClockHandsForOrderOfMagi - 1) )
													angleVariable = angleVariable - fullAngle * 2 / ( numberOfClockHandsForOrderOfMagi - 1);
												coreVariable = angleVariable;
												colorIntervalVariable = ( 2 * fullAngle ) / ( ( numberOfColorsForOrderOfMagi - 1 ) * ( numberOfClockHandsForOrderOfMagi - 1) );
												//angle = 0;//Testing Purposes Only.
												if ( origionalpr.getArgb( x, y ) == magentaNum )//shitBrownNum )//origionalpr.getArgb(x, y) == magentaNum )// == magecoreVariable// == webBlackNum
													if ( coreVariable < colorIntervalVariable  + colorDisplacement)//For Normal Rainbow Use This Instead Of The Others
														color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorDisplacement, blue, green);
													else
														color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorIntervalVariable - colorDisplacement, green, blue);
												else//*/
													if ( coreVariable < colorIntervalVariable  + colorDisplacement)//For Normal Rainbow Use This Instead Of The Others
														color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorDisplacement, green, blue);
													else
														color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorIntervalVariable - colorDisplacement, blue, green);//*
												pw.setArgb( x, y, (int)(255 * 16777216 + (int)color.RGB[0] * 65536 + (int)color.RGB[1] * 256 + (int)color.RGB[2]));//setArgb
												greenBlueGreenUsed = true;
											}
											else
												if ( basispr.getArgb( x, y ) == pinkNum )
												{//304 + 244 = 548 // 656 //Need Correction For Screen Size !!
													coreVariable = x - 656 - 628 * xSlider / ( fullAngle / 10 );
													while (coreVariable < 0)
														coreVariable = coreVariable + 628;
													while (coreVariable > 628)
														coreVariable = coreVariable - 628;
													colorIntervalVariable =  628 / (numberOfColorsInTheRainbow - 1 );
												}
												else
													someTargetColorHit = false;
					//End Of Basis Image Switch System
					if (otherBrowserColorHit == true)
						pw.setArgb( x, y, origionalpr.getArgb( x, y ) );
					else
						if ( greenBlueGreenUsed == false )
							if ( someTargetColorHit == true)//numberOfClockHandsForOrderOfMagi  //greenBlueGreenUsed
							{
								//	if ( coreVariable >= colorDisplacementVariable && coreVariable < (numberOfColorsInTheRainbow - 1) * colorIntervalVariable  + colorDisplacement)//For Purple Outside Ring
								//{//Retain Below If Else And Use New Variable Names And Equate Them With If Switch Below New Variable Name Comment Above // Make html Text Flip shitBrownNum Color!
								if ( origionalpr.getArgb( x, y ) == magentaNum )//shitBrownNum )//origionalpr.getArgb(x, y) == magentaNum )// == magecoreVariable// == webBlackNum
									if ( coreVariable < colorIntervalVariable  + colorDisplacement)//For Normal Rainbow Use This Instead Of The Others
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorDisplacement, purple, blue);
									else if ( coreVariable < ( 2 * colorIntervalVariable  + colorDisplacement) )
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorIntervalVariable - colorDisplacement, blue, teal);
									else if ( coreVariable < ( 3 * colorIntervalVariable  + colorDisplacement) )		
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 2 * colorIntervalVariable - colorDisplacement, teal, pink);
									else if ( coreVariable < ( 4 * colorIntervalVariable  + colorDisplacement) )
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 3 * colorIntervalVariable - colorDisplacement, pink, yellow);
									else if ( coreVariable < ( 5 * colorIntervalVariable  + colorDisplacement) )
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 4 * colorIntervalVariable - colorDisplacement, yellow, orange);
									else
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 5 * colorIntervalVariable - colorDisplacement, orange, red);
								else//*/
									if ( coreVariable < colorIntervalVariable  + colorDisplacement)//For Normal Rainbow Use This Instead Of The Others
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorDisplacement, red, orange);
									else if ( coreVariable < ( 2 * colorIntervalVariable  + colorDisplacement) )
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - colorIntervalVariable - colorDisplacement, orange, yellow);
									else if ( coreVariable < ( 3 * colorIntervalVariable  + colorDisplacement) )		
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 2 * colorIntervalVariable - colorDisplacement, yellow, green);
									else if ( coreVariable < ( 4 * colorIntervalVariable  + colorDisplacement) )
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 3 * colorIntervalVariable - colorDisplacement, green, teal);
									else if ( coreVariable < ( 5 * colorIntervalVariable  + colorDisplacement) )
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 4 * colorIntervalVariable - colorDisplacement, teal, blue);
									else
										color.ColorSliderFunction(colorIntervalVariable, coreVariable - 5 * colorIntervalVariable - colorDisplacement, blue, purple);// */
								pw.setArgb( x, y, (int)(255 * 16777216 + (int)color.RGB[0] * 65536 + (int)color.RGB[1] * 256 + (int)color.RGB[2]));//setArgb
							}
							else
								if ( origionalpr.getArgb( x, y ) != magentaNum )//shitBrownNum )
									pw.setArgb( x, y, basispr.getArgb( x, y ) );
								else
									pw.setArgb( x, y, neonGreenNum);//shitBrownNum);//pr.getArgb( x, y ) );
				}
			}
			imageView.setImage(writableImage);

			secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle) + 1] = new StackPane();
			//System.out.println("secondStackPane Array Value" + ( (int)(secondFRateDivisor * xSlider/fullAngle) + 1 ));
			//secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle) + 1].getChildren().add(browser);
			//secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle) + 1].getChildren().remove(0);
			secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle) + 1].getChildren().add(imageView);
			//End Of xSlider Loop For .3db Video Production .3da Should Be For Abstract 3-D Video Compression .3dc Should For Degraded 3-D Video Compression .3dm Should Be For Standard 3D Videos
			//.3dv Should Be For 3-D Virtual Environment Integration And Interoperability With 2-D Pictures And Video And Interactive Audio Management.
			secondScene[(int)(secondFRateDivisor * xSlider/fullAngle) + 1] = new Scene(secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle) + 1]);//Each A 3D Image
			//origionalBrowserImage = secondStackPane[(int)(secondFRateDivisor * xSlider/fullAngle) + 1].getScene().snapshot(bufferPicure);
			//secondaryStage.setFullScreen(true);
			//secondaryStage.show();



			secondaryStage.setScene(secondScene[(int)(secondFRateDivisor * xSlider/fullAngle) + 1]);

			System.out.println(Dim);

			secondaryStage.setFullScreen(true);

			secondaryStage.show();

			if ( xSlider == 0 )//(int)Math.round(colorDisplacement) + radialDistance * 2 * Math.PI / numberOfClockHandsForRainbow / 2)
			{
				File outputFile = new File("C:/TestImage.png");
				BufferedImage bImage = SwingFXUtils.fromFXImage(secondScene[(int)(secondFRateDivisor * xSlider/fullAngle) + 1].snapshot(null), null);
				try {
					ImageIO.write(bImage, "png", outputFile);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			try {
				secondEnc.encodeImage( SwingFXUtils.fromFXImage(secondScene[(int)(secondFRateDivisor * xSlider/fullAngle) + 1].snapshot(null), null ) ); }
			catch(IOException ie4) { ie4.printStackTrace(); }//*/

			//enc.encodeImage( SwingFXUtils.fromFXImage( imageView.getImage(), null ) );
			
			//Save JavaScript With JavaScript Scroll Changes
			/*try ( PrintWriter out = new PrintWriter(secondJavaScriptFile.getPath() ) )
			{
				out.println("Is Writing");
				out.close();
			}
			catch(IOException ie) { ie.printStackTrace(); }// */
			
			if ( scrollOnePixelCounter == 11 )
			{
				scrollDownValue++;
				System.out.println( "scrollDownValue:" + scrollDownValue );
				try {
					writer = new PrintWriter( "C:/Users/AllAV/Desktop/FWA Website/pixies.zone/scrollContinuously444.js" );//, "UTF-8");
					writer.println("function scrollContinuously( timeInterval )\r\n" +
						"{\r\n" + 
						"	timeInterval = 444;\r\n" + 
						"	window.setInterval( scrollWin, timeInterval );\r\n" + 
						"}\r\n" + 
						"function scrollWin()\r\n" + 
						"{\r\n" + 
						"    window.scrollBy( 0, " + ( scrollDownValue * 100 ) + " );\r\n" + 
						"}");// */
					writer.close();
				}
				catch(IOException ie3) { ie3.printStackTrace(); }
				/*try ( PrintWriter out = new PrintWriter(secondJavaScriptFile.getPath() ) )
				{
					out.println("function scrollContinuously( timeInterval )\r\n" + 
						"{\r\n" + 
						"	timeInterval = 444;\r\n" + 
						"	window.setInterval( scrollWin, timeInterval );\r\n" + 
						"}\r\n" + 
						"function scrollWin()\r\n" + 
						"{\r\n" + 
						"    window.scrollBy( 0, " + scrollDownValue * 100 + " );\r\n" + 
						"}");
					out.close();
				}
				catch(IOException ie) { ie.printStackTrace(); }// */
				scrollOnePixelCounter = 0;
				secondBrowser.getEngine().setJavaScriptEnabled(true);
				//secondBrowser.getEngine().executeScript("scrollContinuously");
				secondBrowser.getEngine().load("file:///C:/Users/AllAV/Desktop/FWA%20Website/pixies.zone/PixiesTest%20-%20Copy%20(2).html");
				secondBrowser.getEngine().reload();
				//try { synchronized (secondBrowser) {
				//	secondBrowser.wait();
				//} }
				//catch (InterruptedException exc2) { throw new Error("Unexpected interruption", exc2); }
				
				//try { secondBrowser.wait(); }
				//catch (InterruptedException exc2) { throw new Error("Unexpected interruption", exc2); }
				
			}
			else
				scrollOnePixelCounter++;
			//System.out.println(secondJavaScriptFile.toString());
			//secondBrowser.getEngine().load("file:///C:/Users/AllAV/Desktop/FWA%20Website/pixies.zone/PixiesTest%20-%20Copy%20(2).html");
			//secondBrowser.getEngine().reload();

			fullScreened = secondaryStage.isFullScreen();

			/*secondScene[(int)(secondFRateDivisor * xSlider/fullAngle) + 1].setOnKeyReleased(new EventHandler<KeyEvent>()
			{
				@Override
				public void handle(KeyEvent event)
				{
					if ( event.isAltDown() == true)
					{
						switch (event.getCode())
						{
						case ENTER: secondaryStage.setFullScreen(!secondaryStage.isFullScreen()); break;
						}
					}
				}
			});// */

			xSlider = xSlider + interval;
			System.out.println(Dim);

			//}
			//Thread.sleep(2000);}
			//catch (Exception ex) {ex.printStackTrace();}
		}
		try { secondEnc.finish(); }
		catch(IOException ie) { ie.printStackTrace(); }//*/

		//boolean first = true;
		//final WebView view = new WebView();
		/*secondBrowser.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {

		    @Override
		    public void changed(ObservableValue<? extends Worker.State> ov, Worker.State t, Worker.State t1) {
		        System.out.println(t1);
		        if(t1.equals(State.SUCCEEDED) ) {//&& first) {
		            //first = false;
		        	secondBrowser.getEngine().reload();
		        }
		    }
		});
		
		
		secondBrowser.getEngine().getLoadWorker().stateProperty().addListener(
	            new ChangeListener<Worker.State>() {
	                public void changed(ObservableValue ov, 
	                                    Worker.State oldState, Worker.State newState) {
	                    if (newState == Worker.State.SUCCEEDED) {
	                        //some append js code here
	                    	secondBrowser.getEngine().setJavaScriptEnabled(true);
	        				//secondBrowser.getEngine().executeScript("scrollContinuously");
	        				secondBrowser.getEngine().load("file:///C:/Users/AllAV/Desktop/FWA%20Website/pixies.zone/PixiesTest%20-%20Copy%20(2).html");
	        				secondBrowser.getEngine().reload();
	                    }
	                }
	            });// */
		//encFinished = true;
		//}
		/*webEngine.getLoadWorker().stateProperty().addListener(
	        new ChangeListener<State>() {
	            public void changed(ObservableValue ov, State oldState, State newState) {
	                if (newState == State.SUCCEEDED) {
	                    secondaryStage.setTitle(webEngine.getLocation());
	                }
	            }
	        });*/
		/*browser.getEngine().getLoadWorker().stateProperty().addListener(
			  (ObservableValue<? extends worker.State> observable,
			    worker.State oldValue,
			    worker.State newValue) -> {
			    if( newValue != worker.State.SUCCEEDED ) {
			      return;
			    }

			    // Your logic here
			  } );*/

		//if (worker.State.SUCCEEDED == true)
		//{


		//}
		/*secondScene.setOnKeyReleased(new EventHandler<KeyEvent>()
	{
		@Override
		public void handle(KeyEvent event)
		{
			if ( event.isAltDown() == true)
			{
				switch (event.getCode())
				{
					case ENTER: secondaryStage.setFullScreen(!secondaryStage.isFullScreen()); break;
				}
			}
		}
	});//*
		secondScene[(int)secondFRateDivisor].setOnKeyReleased(new EventHandler<KeyEvent>()
		{
			@Override
			public void handle(KeyEvent event)
			{
				if ( event.isAltDown() == true)
				{
					switch (event.getCode())
					{
					case ENTER: secondaryStage.setFullScreen(!secondaryStage.isFullScreen()); break;
					}
				}
			}
		});
	//*/
		//browser.snapshot(sP, origionalTextPicture);
	}

	public static void main(String[] args) throws IOException
	{
		launch(args);

	}

}
